//
//  myResumeCellName.swift
//  LeDian
//
//  Created by 三秒文化 on 16/3/18.
//  Copyright © 2016年 51ledian. All rights reserved.
//

import UIKit
import SDWebImage

class myResumeCellName: LDBaseRecFinderCell {
    
    var nameLab:UILabel?
    var workStatus:UILabel?
    var headImageView:UIImageView?
    
    var genderBtn:UIButton?
    var cityBtn:UIButton?
    var experienceBtn:UIButton?
    var eduBtn:UIButton?
    
    var zhaoPic:UIImageView?
    var jobName:UILabel?
    var expectSalary:UILabel?
    
    var expectBtn:UIButton?
    var expectTag:UILabel?
    
    let imgHeadW:CGFloat = IPHONE6UP ? 60:40
    
    var models = myResumeCellNameModel() {
        
        didSet{
            updateFrames()
        }
    }
    
    var divideLine1 = UIImageView.setupDivideLine_H(LDFrame.ScreenWidth - Margin_V * 8)
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setDefaultContent()
        setupFrame()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
    }
    func setDefaultContent() {
        
        nameLab = UILabel.setDetailsLab("Name", fontSize: 16, titleColor: LDFontColor.Green,Alignment: nil)
        workStatus = UILabel.setDetailsLab("", fontSize: 13, titleColor: LDFontColor.LightGray,Alignment: .Left)
        headImageView = UIImageView.setDefaultGoundImg("default_header", radius: imgHeadW/2)
        genderBtn = UIButton()
        genderBtn?.hidden = true
        
        
        cityBtn = UIButton.setLoactionBtn()
        experienceBtn = UIButton.setExperienceBtn()
        eduBtn = UIButton.setEduBtn()
        
        jobName = UILabel.setDetailsLab("视觉设计师", fontSize: 16, titleColor: LDFontColor.Green,Alignment: nil)
        expectSalary = UILabel.setDetailsLab("￥ 10K-10K", fontSize: 14, titleColor: LDFontColor.DeepGray,Alignment: nil)
        expectBtn = UIButton.setDetailsBtn("期望行业 ", picName: "期望行业", btnBackColor: LDGolbalColor.White, titleColor: LDFontColor.DeepGray)
        expectBtn?.titleLabel?.font = LDFont.Font15
        expectTag = UILabel.setDetailsLab("", fontSize: 14, titleColor:LDFontColor.DeepGray,Alignment: .Left)
        
        gapView.addSubview(nameLab!)
        gapView.addSubview(workStatus!)
        gapView.addSubview(headImageView!)
        gapView.addSubview(genderBtn!)
        gapView.addSubview(cityBtn!)
        gapView.addSubview(experienceBtn!)
        gapView.addSubview(eduBtn!)
        gapView.addSubview(jobName!)
        gapView.addSubview(expectSalary!)
        gapView.addSubview(expectBtn!)
        gapView.addSubview(expectTag!)
        
        gapView.addSubview(divideLine1)
    }
    func updateFrames() {
        
        nameLab?.text = models.name
        workStatus?.text = models.status
        let url = NSURL(string: LDCommentAPI.getPicApi(models.logo))
        
        headImageView?.sd_setImageWithURL(url, placeholderImage: UIImage(named: "default_header"))
        
        if models.sex == "男" {
            
            genderBtn?.setImage(UIImage.init(named: "common_icon_male"), forState: .Normal)
            genderBtn?.hidden = false
            
        } else if models.sex == "女"{
            
            genderBtn?.setImage(UIImage.init(named: "common_icon_female"), forState: .Normal)
            genderBtn?.hidden = false
        } else {
            
            genderBtn?.hidden = true
        }
        
        let cityname = models.expectcity.characters.count > 0 ? models.expectcity:"城市"
        cityBtn?.setTitle(cityname, forState: .Normal)
        
        let experience = models.experience.characters.count > 0 ? models.experience:"经验"
        experienceBtn?.setTitle(experience, forState: .Normal)
        
        let eduTitle = models.edu.characters.count > 0 ? models.edu : "学位"
        eduBtn?.setTitle(eduTitle, forState: .Normal)
        
        jobName?.text = models.expectjobcategory.characters.count > 0 ? models.expectjobcategory:"期望工作"
        
        if models.expectsalary.characters.count > 0 {
            
            let attri = NSMutableAttributedString.init(string: "￥ \(models.expectsalary)")
            attri.addAttributes([NSForegroundColorAttributeName:LDFontColor.Red], range: NSRange.init(location: 0, length: 1))
            expectSalary?.attributedText = attri
            
        } else {
            
            expectSalary?.text = "期望薪资未录入"
        }
        
        var strtilte = ""
        for item in models.expectjobindustries {
            
            var str = String()
            if (item["industry"] != nil) {
                str = item["industry"] as? String ?? "NULL"
            }
            
            strtilte.appendContentsOf(" | \(str)")
        }
        
        expectTag?.text = strtilte
        
        
        let textsize = CGSizeMake(120, 15)
        
        let size1 = cityname.boundingRectWithSize(textsize, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName:LDFont.Font14], context: nil)
        let size2 = experience.boundingRectWithSize(textsize, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName:LDFont.Font14], context: nil)
        let size3 = eduTitle.boundingRectWithSize(textsize, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName:LDFont.Font14], context: nil)
        
        let textsizeName = CGSizeMake(200, 20)
        let nameTitle = models.name.boundingRectWithSize(textsizeName, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName:LDFont.Font16], context: nil)
        
        
        
        nameLab?.snp_updateConstraints(closure: { (make) in
            
            make.width.equalTo(nameTitle.size.width + LDMargin_V*2)
        })
        cityBtn!.snp_updateConstraints { (make) in
            
            make.width.equalTo(size1.size.width + LDMargin_V*5.5)
        }
        experienceBtn!.snp_updateConstraints { (make) in
            
            make.width.equalTo(size2.size.width + LDMargin_V*5.5)
        }
        eduBtn!.snp_updateConstraints { (make) in
            
            make.width.equalTo(size3.size.width + LDMargin_V*5.5)
        }
        
    }
    
    func setupFrame() {
        
        nameLab?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo(gapView.snp_top).offset(Margin_V*3)//(Margin_V*3)
            make.left.equalTo(Margin_V*3)
            make.size.equalTo(CGSizeMake(0, 25))
        })
        workStatus?.snp_makeConstraints(closure: { (make) in
            make.left.equalTo((nameLab?.snp_right)!).offset(Margin_V)
            make.centerY.equalTo(nameLab!)
            make.size.equalTo(CGSizeMake(120, 20))
            
        })
        headImageView?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo(Margin_V*1)
            make.right.equalTo(-Margin_V*2)
            make.width.height.equalTo(imgHeadW)
        })
        
        
        genderBtn?.snp_makeConstraints(closure: { (make) in
            make.bottom.equalTo((headImageView?.snp_bottom)!).offset(Margin_V/2)
            make.right.equalTo(headImageView!.snp_right).offset(-Margin_V)
            make.width.equalTo(20)
            make.height.equalTo(20)
        })
        //
        
        cityBtn?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo((nameLab?.snp_bottom)!).offset(Margin_V*2)
            make.left.equalTo(nameLab!)
            make.width.equalTo(35)
            make.height.equalTo(15)
        })

        experienceBtn?.snp_makeConstraints(closure: { (make) in
            make.left.equalTo((cityBtn?.snp_right)!).offset(5)
            make.top.height.equalTo(cityBtn!)
        })
        eduBtn?.snp_makeConstraints(closure: { (make) in
            make.left.equalTo((experienceBtn?.snp_right)!).offset(5)
            make.top.height.equalTo(cityBtn!)
        })
        
        
        divideLine1.snp_makeConstraints { (make) in
            make.top.equalTo((cityBtn?.snp_bottom)!).offset(Margin_V*3)
            make.left.equalTo(Margin_V*2)
            make.right.equalTo(-Margin_V*2)
            make.height.equalTo(1)
        }
        jobName?.snp_makeConstraints(closure: { (make) in
            make.left.equalTo(nameLab!)
            make.top.equalTo(divideLine1.snp_bottom).offset(Margin_V*2)
            //            make.size.equalTo(CGSizeMake(80, 25))
            make.height.equalTo(25)
        })
        expectSalary?.snp_makeConstraints(closure: { (make) in
            make.centerY.equalTo(jobName!)
            make.left.equalTo((jobName?.snp_right)!).offset(Margin_V*2)
            make.size.equalTo(CGSizeMake(140, 20))
        })
        expectBtn?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo((jobName?.snp_bottom)!).offset(Margin_V)
            make.left.equalTo(nameLab!)
            //            make.size.equalTo(CGSizeMake(80, 28))
            make.width.equalTo(80)
        })
        expectTag?.snp_makeConstraints(closure: { (make) in
            make.top.height.equalTo(expectBtn!)
            make.left.equalTo((expectBtn?.snp_right)!)
            make.size.equalTo(CGSizeMake(300, 25))
        })
    }
}
class myResumeCellNameModel:NSObject {
    
    var height:CGFloat = 165
    //models数据
    var name = "" // 姓名
    var sex = "" // 性别
    var experience = "" // 工作经验年限
    var edu = ""// 学历
    var logo = ""
    var expectjobcategory = "" // 期望工作类别
    var expectcity = ""        // 期望工作城市
    var expectsalary = "" // 期望工作薪资
    var status = ""                 // 当前状态
    var jobtitle = ""
    var expectjobindustriescount = 0       // 期望工作所属行业数目
    var expectjobindustries = [AnyObject]()      // 期望工作所属行业数组
    
    var shareh5 = ""
    var sharelogo = ""
    var sharetitle = ""
    var sharedesc = ""
    
}
